import { createRouter, createWebHistory } from "vue-router";
import Home from "../views/Home.vue";

const routes = [
	{
		path: "/login",
		name: "login",
		component: () => import("../views/login/Login.vue"),
	},
	{
		path: "/",
		name: "Home",
		component: Home,
		redirect: '/weChat',
		children: [
			{
				path: "/weChat",
				name: "weChat",
				component: () => import("../views/weChat/WeChat.vue"),
			},
			{
				path: "/contacts",
				name: "contacts",
				component: () => import("../views/communication/Communication.vue"),
			},
			{
				path: "/discover",
				name: "discover",
				component: () => import("../views/find/Discover.vue"),
			},
			{
				path: "/profile",
				name: "profile",
				component: () => import("../views/profile/Profile.vue"),
			},
		],
	},
	{
		path: "/groupChat",
		name: "groupChat",
		component: () => import("../views/addAction/GroupChat.vue"),
	},
	{
		path: "/addfriends",
		name: "addfriends",
		component: () => import("../views/addAction/AddFriends.vue"),
	},

	{
		path: "/addfriends/add",
		name: "add",
		component: () => import("../views/addAction/addFriend/AddFriendFromLetda.vue"),
	},
	{
		path: "/addfriends/face",
		name: "face",
		component: () => import("../views/addAction/addFriend/FaceToFace.vue"),
	},
	{
		path: "/addfriends/phoneCom",
		name: "phoneCom",
		component: () => import("../views/addAction/addFriend/PhoneCommuni.vue"),
	},
	{
		path: "/saoma",
		name: "saoma",
		component: () => import("../views/addAction/SaoMa.vue"),
	},
	{
		path: "/givemoney",
		name: "givemoney",
		component: () => import("../views/addAction/GiveMoney.vue"),
	},
	{
		path: "/chatWindows",
		name: "chatWindows",
		component: () => import("../views/weChat/ChatWindows.vue"),
	},
	{
		path: "/userDetail",
		name: "userDetail",
		component: () => import("../views/profile/profileDetail/UserDetail.vue"),
	},
	// 从通讯录打开之后的跳转
	{
		path: "/friendDetail",
		name: "friendDetail",
		component: () => import("../views/communication/comm/FriendDetail.vue"),
	},
	{
		path: "/friendDetail/friendPermiss",
		name: "friendPermiss",
		component: () => import("../views/communication/comm/FriendPermiss.vue"),
	},
	{
		path: "/friendDetail/beizhu",
		name: "beizhu",
		component: () => import("../views/communication/comm/BeiZhu.vue"),
	},
	{
		path: "/friendDetail/infomore",
		name: "infomore",
		component: () => import("../views/communication/comm/infoMore.vue"),
	},
	{
		path: "/aaa",
		name: "aaa",
		component: () => import("../views/weChat/aaa.vue"),
	},
	{
		path: "/profileDetail/changeDetail",
		name: "changeDetail",
		component: () => import("../views/profile/profileDetail/ChangeDetail.vue"),
	},
];

const router = createRouter({
	history: createWebHistory(process.env.BASE_URL),
	routes,
});

export default router;


router.beforeEach((to,from,next) => {
	if(to.path === '/login') {
		next();
	}else{
		if (!localStorage.getItem("token")) 
				next('/login')
		else 
			next()
	}

})
